function value = MaxWaveHeightConstraint(x)

global n pointIdentifiers hitViolation WaveHeightLimit WP3D WP3DStandard
global WaveHeight TimeResolution

HitStorm = WP3DStandard;
HitStorm = WP3D.*WaveHeight;
p = size(HitStorm, 3);
inter2 = zeros(p);

dist1 = [];
for i = 2:n+2
    dist1 = [dist1, repmat(pointIdentifiers(i, 3), 1, ceil(...
        pointIdentifiers(i, 4)/TimeResolution)-ceil(...
        pointIdentifiers(i-1, 4)/TimeResolution))];
end

for i = 1:length(dist1)
    inter = HitStorm(:, :, i);
    inter2(i) = dist1(i)*length(inter(inter > WaveHeightLimit))...
        /length(inter(inter > 0));
end

value = sum(nansum(inter2));
hitViolation = value;